package com.fenghongzhang.day003_mvp.mvp.view;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.os.Bundle;
import android.util.Log;

import com.fenghongzhang.day003_mvp.DaggerFoodComponent;
import com.fenghongzhang.day003_mvp.FoodModule;
import com.fenghongzhang.day003_mvp.R;
import com.fenghongzhang.day003_mvp.adapter.FoodAdapter;
import com.fenghongzhang.day003_mvp.entity.Food;
import com.fenghongzhang.day003_mvp.mvp.contract.FoodContract;
import com.fenghongzhang.day003_mvp.mvp.model.FoodModel;
import com.fenghongzhang.day003_mvp.mvp.presenter.FoodPresenter;
import com.fenghongzhang.lib.mvp.view.BaseActivity;

import java.util.List;

/**
 * 用rv 展示大虾串. mvp 下载和展示
 */
public class MainActivity extends BaseActivity<FoodPresenter> implements FoodContract.IFoodView {

    private static final String TAG = "MainActivity";
    private RecyclerView rv;

    @Override
    public int bindLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        rv = (RecyclerView) findViewById(R.id.rv);
        Log.i(TAG, "initView: ");
    }

    @Override
    public void initData() {
        mPresenter = new FoodPresenter(new FoodModel(),this);
//        DaggerFoodComponent.builder().foodModule(new FoodModule(this)).build().inject(this);
        mPresenter.getData();
    }

    @Override
    public void showMsg(String s) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showFood(List<Food.DataBean> food) {
        Log.i(TAG, "showFood: ");
        final FoodAdapter foodAdapter = new FoodAdapter(R.layout.rv_layout, food);
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                rv.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
                rv.setAdapter(foodAdapter);
            }
        });

    }
}
